package top.continew.admin.controller.distribute;

import cn.shengchao.examstar.rpc.base.TransResult;
import cn.shengchao.examstar.rpc.distribute.DistributeUserInviteApi;

import cn.shengchao.examstar.rpc.wecom.api.CpUserServiceInviteApi;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.business.service.UserHelperService;
import top.continew.admin.req.DistributeJmsYgBatchInviteChangeRto;
import top.continew.admin.req.QywxJmsYgBatchInviteChangeRto;
import top.continew.admin.req.user.SysUserQuery;
import top.continew.admin.system.model.vo.UserInfoVo;
import top.continew.admin.system.model.vo.UserWithRoleVo;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
import top.continew.starter.web.model.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: examstar-manger-api
 * @description: 分销支撑的Rest api
 * @author: Xiong weiqiang
 * @create: 2025-03-26 17:04
 */
@Tag(name = "分销-邀请变更")
@RestController
@RequestMapping("/invite/change")
@RequiredArgsConstructor
public class InviteChangeController {
    @DubboReference
    private DistributeUserInviteApi distributeUserInviteApi;
    @DubboReference
    private CpUserServiceInviteApi cpUserServiceInviteApi;


    @Operation(summary = "员工分销关系替换", description = "员工分销关系替换")
    @PostMapping("/distributeJmsYgReplace")
    R<String> distributeJmsYgReplace(@Validated @RequestBody DistributeJmsYgBatchInviteChangeRto distributeJmsYgBatchInviteChangeRto) {
        TransResult<String> transResult= distributeUserInviteApi.batchUpdateUserInviteRecordForJmsYg(distributeJmsYgBatchInviteChangeRto.toReq());
        if (transResult.getSuccess()){
            return R.ok();
        }else {
            return R.fail(R.fail().getCode(),transResult.getMessage());
        }
    }

    @Operation(summary = "员工企微邀请关系替换", description = "员工企微邀请关系替换")
    @PostMapping("/qywxJmsYgReplace")
    R<String> qywxJmsYgReplace(@Validated @RequestBody QywxJmsYgBatchInviteChangeRto qywxJmsYgBatchInviteChangeRto) {
        TransResult<String> transResult= cpUserServiceInviteApi.batchUpdateUserInviteRecordForJmsYg(qywxJmsYgBatchInviteChangeRto.toReq());
        if (transResult.getSuccess()){
            return R.ok();
        }else {
            return R.fail(R.fail().getCode(),transResult.getMessage());
        }
    }


}